import { useState } from 'react';

import Axios from 'axios';

export const useAutoCompleteBasic = (): [string[], (value: string) => any] => {
  const [dataSource, setDataSource] = useState<string[]>([]);

  const handleSearch = (value: string) => {
    Axios.get<any, string[]>('/_api/auto-complete-basic', {
      params: {
        value,
      },
    })
      .then(res => {
        setDataSource(res);
      });
  };
  return [dataSource, handleSearch];
};